package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import javax.swing.ImageIcon;

import entity.User;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.awt.Label;

import javax.swing.JInternalFrame;
import java.awt.Color;


/**
 * Opening the main frame for the costumer
 *
 */
public class CustomerGui extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	User user;
	static String ID;
	public final static ImageIcon IMG_SERVER_BACKGROUND = new ImageIcon("images/Server Background.jpg");
	private JLabel label;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CustomerGui frame = new CustomerGui(ID);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the Customer Gui frame.
	 */

	
	public CustomerGui(String id) {
		
		this.ID=id;
		System.out.println("in CustomerGui  "+ID );
		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 900, 600);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);
		
		JMenuItem mntmExit = new JMenuItem("Exit");
		mntmExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			
				JOptionPane.showInternalMessageDialog(null, "Bye Bye");
				dispose();
			}
		});
		mntmExit.setIcon(new ImageIcon(CustomerGui.class.getResource("/com/sun/java/swing/plaf/windows/icons/Error.gif")));
		mnFile.add(mntmExit);
		
		JMenu mnHelp = new JMenu("Help");
		menuBar.add(mnHelp);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblWelcomeToSgi = new JLabel("Welcome to SGi System");
		lblWelcomeToSgi.setBounds(4864, 14, 235, 22);
		lblWelcomeToSgi.setFont(new Font("Tahoma", Font.ITALIC, 18));
		
		JButton btnNewButton = new JButton("Samples");
		btnNewButton.setBounds(404, 323, 136, 70);
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SampleCus frame = new SampleCus(ID);
				frame.setVisible(true);
			
				dispose();
			}
		});
		
		JButton btnSearchInArchive = new JButton("Search in Archive");
		btnSearchInArchive.setBounds(229, 323, 143, 70);
		
		JButton btnComplaint = new JButton("Complaint");
		btnComplaint.setBounds(584, 323, 133, 70);
		btnComplaint.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try{
					btnComplaintActionPerformed(e);
				dispose();
					
				} catch(IOException e1) {
					e1.printStackTrace();
				}			
				/*CustomerComplaint frame = new CustomerComplaint();
				frame.setVisible(true);*/
			}
		});
		
		JButton btnSubscribe = new JButton("Subscribe");
		btnSubscribe.setBounds(584, 448, 133, 67);
		btnSubscribe.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SubscribingByCustomer frame = new SubscribingByCustomer(ID);
				frame.setVisible(true);
				dispose();
			}
		});
	
		JButton btnPictures = new JButton("Pictures");
		btnPictures.setBounds(404, 446, 136, 70);
		btnPictures.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				PictureCustomer frame = new PictureCustomer(ID);
				frame.setVisible(true);
				dispose();
			}
		});
		
		JLabel lblCustomer = new JLabel("customer");
		lblCustomer.setBounds(5105, 66, 44, 14);
		
		JLabel lblNewLabel = new JLabel("Welcome to SGI System");
		lblNewLabel.setForeground(new Color(50, 205, 50));
		lblNewLabel.setBounds(104, 3, 484, 77);
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 35));
		
		JLabel lblNewLabel_1 = new JLabel("Customer");
		lblNewLabel_1.setBounds(621, 11, 253, 92);
		lblNewLabel_1.setIcon(new ImageIcon("images//customer.jpg"));
		contentPane.setLayout(null);
		contentPane.add(btnPictures);
		contentPane.add(btnSubscribe);
		contentPane.add(btnNewButton);
		contentPane.add(btnComplaint);
		contentPane.add(btnSearchInArchive);
		contentPane.add(lblNewLabel_1);
		contentPane.add(lblNewLabel);
		contentPane.add(lblWelcomeToSgi);
		contentPane.add(lblCustomer);
		contentPane.setLayout(null);
		
		JButton btnPurchases = new JButton("Purchases");
		btnPurchases.setBounds(229, 450, 143, 63);
		btnPurchases.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try{
				ShowPurchasesPictures frame = new ShowPurchasesPictures(ID);
				frame.setVisible(true);
				dispose();
				}catch(Exception e1){e1.printStackTrace();}
			}
		});
		contentPane.add(btnPurchases);
		
		JLabel lblNewLabel_2 = new JLabel("");
		lblNewLabel_2.setIcon(new ImageIcon("images\\sea.jpg"));
		lblNewLabel_2.setBounds(0, 0, 900, 600);
		contentPane.add(lblNewLabel_2);
		lblNewLabel_2.setLayout(null);
	}

	
	private void btnComplaintActionPerformed(ActionEvent e) throws IOException  {
		CustomerComplaint frame = new CustomerComplaint(this.ID);
		frame.setVisible(true);

	}
}
